//
//  MainViewController.swift
//  我的微博
//
//  Created by teacher on 15/7/27.
//  Copyright © 2015年 itheima. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        addChildViewControllers()
        // 此时 tabBarButton 还没有创建
        print(tabBar.subviews)
    }
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        
    }
    
    /// 添加所有控制器
    private func addChildViewControllers() {
        // 只是添加控制器，并没有创建 tabBar 的 button
        addChildViewController(HomeViewController(), title: "首页", imageName: "tabbar_home")
//        addChildViewController(MessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
//        addChildViewController(UIViewController())
//        addChildViewController(DiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
//        addChildViewController(ProfileTableViewController(), title: "我", imageName: "tabbar_profile")
    }
    
    /// 添加子控制器
    private func addChildViewController(vc: UIViewController, title: String, imageName: String) {
        
        // title 属性会从内向外传递设置
        vc.title = title
        vc.tabBarItem.image = UIImage(named: imageName)
        
        let nav = UINavigationController(rootViewController: vc)
        
        addChildViewController(nav)
    }
}
